package com.example.mongodb1.controller;


import com.example.mongodb1.entity.Form;
import com.example.mongodb1.service.FormService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/form")
@AllArgsConstructor
public class FormController {
    final private FormService formService;

    @PostMapping("/save")
    public Form save(@RequestBody Form form) {
        return formService.saveForm(form);
    }


    @GetMapping("/get")
    public Form getFormById(@RequestParam("id") String id) {
        return formService.getForm(id);
    }

    @GetMapping("/list")
    public List<Form> getForms() {
        return formService.getForms();
    }

    @PostMapping("/save_data")
    public Map<String,Object> saveData(String formId,@RequestBody Map<String,Object> data) {
        formService.saveFormData(formId,data);
        return data;
    }
}
